package com.tcpengine.net;

import com.tcpengine.client.LogView;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class TcpHandler extends ChannelInboundHandlerAdapter {
	
	private LogView m_logView = null;
    public TcpHandler(LogView logView) {
    	m_logView = logView;
    }
	
	@Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        
		// System.out.println("client receive msg:"+msg.toString());
		m_logView.println("tcp收到二进制消息");
		
		 Msg recvMsg = Encoder.decode((ByteBuf)msg);
         if(null != recvMsg) {
         	GameProcess.handle(ctx.channel(), recvMsg, NetService.WS_TYPE, m_logView);
         }
		
		
//		 BinaryWebSocketFrame binFrame = (BinaryWebSocketFrame)frame;
//         Msg recvMsg = Encoder.decode(binFrame.content());
//         if(null != recvMsg) {
//         	GameProcess.handle(ctx.channel(), recvMsg, NetService.WS_TYPE, m_logView);
//         }
		
		
		// 这里实现
    }
}
